package com.cloud.pet.ops.controller.op;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.commons.Result;
import com.cloud.pet.api.manager.op.EmpManager;
import com.cloud.pet.api.req.uc.CustomerInfoReq;
import com.cloud.pet.api.resp.LoginVo;
import com.cloud.pet.api.resp.op.EmployeeVo;
import com.cloud.pet.api.resp.uc.CustomerInfoVo;

import cn.hutool.extra.servlet.ServletUtil;
import io.swagger.annotations.ApiOperation;

/**
 * 运维员工
 * 
 * @author lw
 * @date 2024/07/17
 */
@RestController
@RequestMapping("emp")
public class EmpController {
    @Resource
    private EmpManager empManager;

    @ApiOperation(value = "根据主键id查询")
    @GetMapping(value = "/getEmpById/{id}")
    public Result<EmployeeVo> getEmpById(@PathVariable("id") Long id) {
        return empManager.getEmpById(id);
    }
    
    @ApiOperation(value = "个人信息完善")
    @PostMapping(value = "/editEmp")
    public Result<Integer> editEmp(@RequestBody EmployeeVo vo) {
        return empManager.editEmp(vo);
    }
    
    @ApiOperation(value = "修改密码")
    @PostMapping(value = "/editPwd")
    public Result<Integer> editPwd(@RequestParam("id") Integer id, @RequestParam("pwd") String pwd,
        @RequestParam("oldPwd") String oldPwd) {
        return empManager.editPwd(id, pwd, oldPwd);
    }
    

    @ApiOperation(value = "发送短信验证码")
    @GetMapping(value = "/sendSmsCode/{phone}")
    public Result<?> sendSmsCode(@PathVariable("phone") String phone, HttpServletRequest request) {
        String clientIp = ServletUtil.getClientIP(request);
        return empManager.sendSmsCode(LoginVo.builder().phoneNumber(phone).ip(clientIp).build());
    }
    
    @ApiOperation(value = "手机验证码登录")
    @PostMapping(value = "/codeLogin")
    public Result<?> codeLogin(@RequestBody LoginVo loginVo, HttpServletRequest request) {
        String clientIp = ServletUtil.getClientIP(request);
        loginVo.setIp(clientIp);
        return empManager.codeLogin(loginVo);
    }

    @ApiOperation(value = "密码登录")
    @PostMapping(value = "/pwdLogin")
    public Result<?> pwdLogin(@RequestBody LoginVo loginVo, HttpServletRequest request) {
        String clientIp = ServletUtil.getClientIP(request);
        loginVo.setIp(clientIp);
        return empManager.pwdLogin(loginVo);
    }
}
